package com.hw.springhbase.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hw.springhbase.service.HbaseService;

@RestController
public class HbaseController {

	@Autowired
	private HbaseService hservice;
	
	@RequestMapping("getAllTable")
	public List<String> getAllTable(){
		return hservice.getAllTableNames();
	}
	
	@RequestMapping("getTableInfo")
	public Map<String,Map<String,String>> getTableInfo(String tableName){
		
		return hservice.getResultScanner(tableName);
	}
	
	// http://localhost:8081/addInfo?tableName=person&rowKey=1&familyName=account&column=role&value=管理员
	
	@RequestMapping("/addInfo")
	public String addInfo(String tableName, String rowKey, String familyName, String column, String value){
		String msg="添加成功！";
		List<String> columns=new ArrayList<String>();
		List<String> values=new ArrayList<String>();
		columns.add(column);
		values.add(value);
		
		String[] a=new String[columns.size()];
		String[] b=new String[values.size()];
		a=columns.toArray(a);
		b=values.toArray(b);
		
		try{
			hservice.putData(tableName, rowKey, familyName, a, b);
		}catch(Exception e){
			msg="添加失败!";
		}
		return msg;
	}
}
